package com.young4j.springdemo.config.elasticsearch;

import com.google.gson.Gson;
import io.searchbox.client.JestClient;
import io.searchbox.client.JestClientFactory;
import io.searchbox.client.config.HttpClientConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @Description
 * @Author yf
 * @Date 2019/1/3 9:41
 **/
@Configuration
@Component
public class ElastisearchConfig {
    @Autowired
    private ElastisearchProperties elastisearchProperties;
    /*@Bean(destroyMethod = "close")
    public JestClient jestClient() throws Exception{
        JestClientFactory factory = new JestClientFactory();
        String clusterNodes = elastisearchProperties.getClusterNodes();
        String[] split = clusterNodes.split(",");
        List<String> hosts = Arrays.asList(split);
        HttpClientConfig.Builder builder = new HttpClientConfig.Builder(hosts);
        builder.maxTotalConnection(elastisearchProperties.getMaxTotalConnection());
        builder.defaultMaxTotalConnectionPerRoute(elastisearchProperties.getMaxDefaultTotalConnection());
        builder.connTimeout(elastisearchProperties.getConnectTimeOut());
        builder.gson(new Gson());
        builder.readTimeout(elastisearchProperties.getReadTimeOut());
        builder.discoveryEnabled(true);
        builder.multiThreaded(true);
        factory.setHttpClientConfig(builder.build());
        JestClient object = factory.getObject();
        return object;
    }*/
}
